#include "QueryResult.h"

QueryResult::QueryResult(MYSQL_RES *result, uint64_t rowCount, uint32_t fieldCount)
    : m_Result(result), m_FieldCount(fieldCount), m_RowCount(rowCount)
{
    MYSQL_FIELD *fields = mysql_fetch_fields(m_Result);
    for (uint32_t i = 0; i < m_FieldCount; i++)
    {
        m_FieldNames[fields[i].name] = i;
    }
    nextRow();
}

QueryResult::~QueryResult()
{
    if (m_Result)
    {
        mysql_free_result(m_Result);
        m_Result = nullptr;
    }
}

bool QueryResult::nextRow()
{
    if (!m_Result)
        return false;
    m_CurrentRow = mysql_fetch_row(m_Result);
    m_Lengths = mysql_fetch_lengths(m_Result);
    if (!m_CurrentRow)
        return false;

    return true;
}
